{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "1.Pytorch_Basic.ipynb",
      "provenance": [],
      "collapsed_sections": [],
      "toc_visible": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "accelerator": "GPU"
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "83OFnkrjFZx1"
      },
      "source": [
        "## 什么是 PyTorch ?\n",
        "\n",
        "PyTorch是一个python库，它主要提供了两个高级功能：\n",
        "\n",
        "- GPU加速的张量计算\n",
        "- 构建在反向自动求导系统上的深度神经网络\n",
        "\n",
        "## 1. 定义数据\n",
        "\n",
        "一般定义数据使用torch.Tensor  ， tensor的意思是张量，是数字各种形式的总称"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "DWkz2K43FW_d",
        "outputId": "ad295687-3ae7-481e-ad20-559580254b63",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "source": [
        "import torch\n",
        "\n",
        "# 可以是一个数\n",
        "x = torch.tensor(666)\n",
        "print(x)"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "tensor(666)\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "p4qRIFWARKjY",
        "outputId": "3776943a-a61f-48c5-d721-e4f7d5b2c05f",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "source": [
        "# 可以是一维数组（向量）\n",
        "x = torch.tensor([1,2,3,4,5,6])\n",
        "print(x)"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "tensor([1, 2, 3, 4, 5, 6])\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "1a4xABr4RM95",
        "outputId": "25c77e8e-304c-48a5-9681-8d67d94d664f",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "source": [
        "# 可以是二维数组（矩阵）\n",
        "x = torch.ones(2,3)\n",
        "print(x)\n"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "tensor([[1., 1., 1.],\n",
            "        [1., 1., 1.]])\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "bh5mcR_fRN_D",
        "outputId": "450d159a-4f2a-4363-d662-de0a7d1a573d",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "source": [
        "# 可以是任意维度的数组（张量）\n",
        "x = torch.ones(2,3,4)\n",
        "print(x)"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "tensor([[[1., 1., 1., 1.],\n",
            "         [1., 1., 1., 1.],\n",
            "         [1., 1., 1., 1.]],\n",
            "\n",
            "        [[1., 1., 1., 1.],\n",
            "         [1., 1., 1., 1.],\n",
            "         [1., 1., 1., 1.]]])\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "rL_CHhxMJHLC"
      },
      "source": [
        "Tensor支持各种各样类型的数据，包括：\n",
        "\n",
        "torch.float32, torch.float64, torch.float16, torch.uint8, torch.int8, torch.int16, torch.int32, torch.int64 。这里不过多描述。\n",
        "\n",
        "创建Tensor有多种方法，包括：ones, zeros, eye, arange, linspace, rand, randn, normal, uniform, randperm, 使用的时候可以在线搜，下面主要通过代码展示。"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "L1tPfIm8KHR6",
        "outputId": "e8606868-00c8-46be-be80-614e49e2a508",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "source": [
        "# 创建一个空张量\n",
        "x = torch.empty(5,3)\n",
        "print(x)"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "tensor([[1.0778e-02, 3.0652e-41, 3.3631e-44],\n",
            "        [0.0000e+00,        nan, 2.3694e-38],\n",
            "        [1.1578e+27, 1.1362e+30, 7.1547e+22],\n",
            "        [4.5828e+30, 1.2121e+04, 7.1846e+22],\n",
            "        [9.2198e-39, 7.0374e+22, 0.0000e+00]])\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "j_tf1_ChRTXt",
        "outputId": "17009ccd-0395-4b35-ed54-1695d8e0f829",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "source": [
        "# 创建一个随机初始化的张量\n",
        "x = torch.rand(5,3)\n",
        "print(x)"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "tensor([[0.6828, 0.6444, 0.4082],\n",
            "        [0.3096, 0.4973, 0.5686],\n",
            "        [0.7827, 0.9595, 0.6359],\n",
            "        [0.7607, 0.8947, 0.2677],\n",
            "        [0.5318, 0.6142, 0.9755]])\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ikJVEFunRWIS",
        "outputId": "0fffeb55-103c-4e0d-a852-97a1c5052c4d",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "source": [
        "# 创建一个全0的张量，里面的数据类型为 long\n",
        "x = torch.zeros(5,3,dtype=torch.long)\n",
        "print(x)"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "tensor([[0, 0, 0],\n",
            "        [0, 0, 0],\n",
            "        [0, 0, 0],\n",
            "        [0, 0, 0],\n",
            "        [0, 0, 0]])\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Q3VVC7-hRXTa",
        "outputId": "714570a9-0722-4488-a7b8-20e32fcaa671",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "source": [
        "# 基于现有的tensor，创建一个新tensor，\n",
        "# 从而可以利用原有的tensor的dtype，device，size之类的属性信息\n",
        "y = x.new_ones(5,3)   #tensor new_* 方法，利用原来tensor的dtype，device\n",
        "print(y)"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "tensor([[1, 1, 1],\n",
            "        [1, 1, 1],\n",
            "        [1, 1, 1],\n",
            "        [1, 1, 1],\n",
            "        [1, 1, 1]])\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "nswc8uK0RYZ5",
        "outputId": "e2dd6470-462d-4435-ac47-99b41ec41d37",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "source": [
        "z = torch.randn_like(x, dtype=torch.float)    # 利用原来的tensor的大小，但是重新定义了dtype\n",
        "print(z)"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "tensor([[-0.1687,  0.6310, -0.6150],\n",
            "        [ 0.7910, -1.8209,  0.6309],\n",
            "        [-0.1282, -0.2183,  0.5011],\n",
            "        [ 0.8218,  0.8931, -0.2142],\n",
            "        [-0.3043, -0.1263,  1.4152]])\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "O-ry_RGyLRJB"
      },
      "source": [
        "## 2. 定义操作\n",
        "\n",
        "凡是用Tensor进行各种运算的，都是Function\n",
        "\n",
        "最终，还是需要用Tensor来进行计算的，计算无非是\n",
        "- 基本运算，加减乘除，求幂求余\n",
        "- 布尔运算，大于小于，最大最小\n",
        "- 线性运算，矩阵乘法，求模，求行列式\n",
        "\n",
        "**基本运算包括：** abs/sqrt/div/exp/fmod/pow ，及一些三角函数 cos/ sin/ asin/ atan2/ cosh，及 ceil/round/floor/trunc 等具体在使用的时候可以百度一下\n",
        "\n",
        "**布尔运算包括：** gt/lt/ge/le/eq/ne，topk, sort, max/min\n",
        "\n",
        "**线性计算包括：** trace, diag, mm/bmm，t，dot/cross，inverse，svd 等\n",
        "\n",
        "不再多说，需要使用的时候百度一下即可。下面用具体的代码案例来学习。"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "QcApnoZ4N4a4",
        "outputId": "a91298e8-33d3-4aaa-d6e6-e5153ef74da4",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "source": [
        "# 创建一个 2x4 的tensor\n",
        "m = torch.Tensor([[2, 5, 3, 7],\n",
        "                  [4, 2, 1, 9]])\n",
        "\n",
        "print(m.size(0), m.size(1), m.size(), sep=' -- ')"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "2 -- 4 -- torch.Size([2, 4])\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "wq-JJbKBRem1",
        "outputId": "1a0e1da8-6e94-4656-ef06-85383b02e41a",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "source": [
        "# 返回 m 中元素的数量\n",
        "print(m.numel())"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "8\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "x2CtLybORhuj",
        "outputId": "b661b15b-2f2b-43c6-cb62-d6c69ba8fb30",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "source": [
        "# 返回 第0行，第2列的数\n",
        "print(m[0][2])"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "tensor(3.)\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "QR-157ITRiuW",
        "outputId": "d08053da-5555-4ad7-8d6d-a3b1834730de",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "source": [
        "# 返回 第1列的全部元素\n",
        "print(m[:, 1])"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "tensor([5., 2.])\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "MOjFlSIzRji_",
        "outputId": "a6b1aeee-9092-4f78-a822-228f04885c87",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "source": [
        "# 返回 第0行的全部元素\n",
        "print(m[0, :])"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "tensor([2., 5., 3., 7.])\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "CYK1sia-P7RC",
        "outputId": "a2d11d87-d02b-4157-a287-09da23bc1f6c",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "source": [
        "# Create tensor of numbers from 1 to 5\n",
        "# 注意这里结果是1到4，没有5\n",
        "v = torch.arange(1, 5)\n",
        "print(v)"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "tensor([1, 2, 3, 4])\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "# 这里需要类型转换，才能进行后面的操作\n",
        "m = m.type(torch.LongTensor)\n",
        "print(m.type())\n",
        "print(v.type())"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "SY2tQfMZ_G_F",
        "outputId": "82e3ec4f-284a-44d5-d2e1-a6f948811870"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "torch.LongTensor\n",
            "torch.LongTensor\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "LN0zTwWNQL70",
        "outputId": "cc3736a7-3529-43f3-fdc0-29e792173830",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "source": [
        "# Scalar product\n",
        "print(m)\n",
        "print(v)\n",
        "m @ v"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "tensor([[2, 5, 3, 7],\n",
            "        [4, 2, 1, 9]])\n",
            "tensor([1, 2, 3, 4])\n"
          ]
        },
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "tensor([49, 47])"
            ]
          },
          "metadata": {},
          "execution_count": 40
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "CDzM9atDQXqo",
        "outputId": "02210ad7-abd2-4680-90ee-e04acd861937",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "source": [
        "# Calculated by 1*2 + 2*5 + 3*3 + 4*7\n",
        "print(m[[0], :])\n",
        "m[[0], :] @ v"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "tensor([[2, 5, 3, 7]])\n"
          ]
        },
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "tensor([49])"
            ]
          },
          "metadata": {},
          "execution_count": 44
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "cRqlJdm3QeYq",
        "outputId": "555bb252-31df-4c36-e758-690d0df309f3",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "source": [
        "# Add a random tensor of size 2x4 to m\n",
        "m + torch.rand(2, 4)"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "tensor([[2.7935, 5.3285, 3.7346, 7.6700],\n",
              "        [4.0578, 2.5264, 1.9603, 9.5590]])"
            ]
          },
          "metadata": {},
          "execution_count": 32
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Zle6ULwDQoMF",
        "outputId": "ce3c61f5-8701-47da-c44c-d56c472a3cee",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "source": [
        "# 转置，由 2x4 变为 4x2\n",
        "print(m.t())\n",
        "\n",
        "# 使用 transpose 也可以达到相同的效果，具体使用方法可以百度\n",
        "print(m.transpose(0, 1))"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "tensor([[2, 4],\n",
            "        [5, 2],\n",
            "        [3, 1],\n",
            "        [7, 9]])\n",
            "tensor([[2, 4],\n",
            "        [5, 2],\n",
            "        [3, 1],\n",
            "        [7, 9]])\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "XqdglZAoR0AZ",
        "outputId": "ade154f5-883f-4d03-918d-c1c12778923c",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "source": [
        "# returns a 1D tensor of steps equally spaced points between start=3, end=8 and steps=20\n",
        "torch.linspace(3, 8, 20)"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "tensor([3.0000, 3.2632, 3.5263, 3.7895, 4.0526, 4.3158, 4.5789, 4.8421, 5.1053,\n",
              "        5.3684, 5.6316, 5.8947, 6.1579, 6.4211, 6.6842, 6.9474, 7.2105, 7.4737,\n",
              "        7.7368, 8.0000])"
            ]
          },
          "metadata": {},
          "execution_count": 34
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "eAu8SIxEShpd",
        "outputId": "825cc93e-0985-4e48-ed1d-fc1fa33c7b6a",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 265
        }
      },
      "source": [
        "from matplotlib import pyplot as plt\n",
        "\n",
        "# matlabplotlib 只能显示numpy类型的数据，下面展示了转换数据类型，然后显示\n",
        "# 注意 randn 是生成均值为 0， 方差为 1 的随机数\n",
        "# 下面是生成 1000 个随机数，并按照 100 个 bin 统计直方图\n",
        "plt.hist(torch.randn(1000).numpy(), 100);"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXAAAAD4CAYAAAD1jb0+AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAO9ElEQVR4nO3df4jkd33H8efL9GxELVEyDddctisalCB6ge01kv5ho5GrikmKLQ1tmtKUtWAgQmgbFarSCilW0z8qlrNJc9BUG/xBQqLVazwIgo3e6Rk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qauLxDVd0L/HjaOdZSVcer6uvd/SdZKp5zp5vquWrJU93DHd1t5v62k+wC3gL8Y5/vu20KHCDJB5P8APh9ZnMEvtwfA5+fdojGnAv8YNnjR5jB0mlNknngQuC+6SZZXXdo4ghwAjhQVbOY8++APwee7fNNT6sCT/LvSY6ucrsMoKreW1XnAbcB1679btPJ2O3zXpb+CXvbNDKOmlOnvyQvAj4NvGvFv2JnRlU90x0a3QXsSfLqaWdaLslbgRNVdbjv9574tVC2UlW9ccRdbwM+B7xvgnFWtV7GJH8EvBV4Q01xkf4G/lvOEi/v0KMkO1gq79uq6jPTzrOeqnoiyUGW5hdmaYL4YuBtSd4MnAn8UpJ/rqo/GPeNT6sR+FqSnL/s4WXAQ9PKMkySvSz9M+ttVfU/087TIC/v0JMkAW4GjlXVR6adZ5gkg1OrtZK8ALiUGfvbrqp3V9Wuqppn6XfyS32UN2yjAgdu7A4B3A+8iaUZ4Vnz98CLgQPdcsd/mHag1SS5IskjwOuAu5N8YdqZYOnyDiwdGvsCS5Nut8/i5R2SfAL4CvDKJI8kuWbamVZxMXAVcEn3u3ikG0HOmp3Awe7v+mssHQPvbZnerPNUeklq1HYagUvSacUCl6RGWeCS1CgLXJIaZYFLUqMscElqlAUuSY36PwA5KIg1UvgqAAAAAElFTkSuQmCC\n",
            "text/plain": [
              "<Figure size 432x288 with 1 Axes>"
            ]
          },
          "metadata": {
            "needs_background": "light"
          }
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Ub2RwbyXS7Qo",
        "outputId": "d30ab507-4f7a-4edd-9cce-1b39e874c0ea",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 265
        }
      },
      "source": [
        "# 当数据非常非常多的时候，正态分布会体现的非常明显\n",
        "plt.hist(torch.randn(10**6).numpy(), 100);"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYMAAAD4CAYAAAAO9oqkAAAABHNC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cer/IssHU2F4LmYuDTwKXtv+2e9lezZgh7BpIkewaSJIuBJAmLgSQJi4EkCYuBJAmLgSQJi4EkCfh/2LPRwmYt8g8AAAAASUVORK5CYII=\n",
            "text/plain": [
              "<Figure size 432x288 with 1 Axes>"
            ]
          },
          "metadata": {
            "needs_background": "light"
          }
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "YXbzAOhqUH-L",
        "outputId": "35f9f1fe-80d3-4cca-96a0-9ce744ec2af8",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "source": [
        "# 创建两个 1x4 的tensor\n",
        "a = torch.Tensor([[1, 2, 3, 4]])\n",
        "b = torch.Tensor([[5, 6, 7, 8]])\n",
        "\n",
        "# 在 0 方向拼接 （即在 Y 方各上拼接）, 会得到 2x4 的矩阵\n",
        "print( torch.cat((a,b), 0))"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "tensor([[1., 2., 3., 4.],\n",
            "        [5., 6., 7., 8.]])\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "HLQv2yN3UeRz",
        "outputId": "0e6faf37-2c5b-4699-ac83-46d5bed354cd",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "source": [
        "# 在 1 方向拼接 （即在 X 方各上拼接）, 会得到 1x8 的矩阵\n",
        "print( torch.cat((a,b), 1))"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "tensor([[1., 2., 3., 4., 5., 6., 7., 8.]])\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "m6UoqOX3Un9z"
      },
      "source": [
        "## One more thing ~\n",
        "\n",
        "其实基本操作还有非常非常多，详细可以查阅官方文档。"
      ]
    }
  ]
}